import { DatePicker } from "antd";
import moment from "moment";
import { NumText  } from "@/pages/OrderModule/common/components/CommonText";
import { Input, Select, BatchSuffixInput } from "@/views/components/PrefixPlaceholder";
import AreaCodeSelect from "@/pages/PurchaseModule/propose/components/Actions/AreaCodeSelect";
import TakeGoodsSelect from "@/views/components/TakeGoodsSelect";

const payMethMap = {
	6: "账期",
	1: "余额",
	9: "抵扣",
};

const { RangePicker } = DatePicker;
const dateFormat = "YYYY-MM-DD HH:mm:ss";
//支付方式
const payMethOptions = Object.keys(payMethMap).map(v => {
	return {
		label: payMethMap[v],
		value: v
	}
})

export default ({ refundStatus, areaOption, takeGoods, refundMethod, refuseType, handleOpenOrderDetailVisible, handleTakeGoodsChange  }) => {
	const defaultColumns = [
		{
			name: "序号",
			code: "index",
			lock: true,
			render: (t, r, i) => i + 1,
			width: 60
		},
		{
			name: "商品唯一码",
			code: "uniqueCode",
			search: {
				order: 3,
				code: "uniqueCodes",
				content: () => <BatchSuffixInput autoMultiLine allowClear clearable placeholder="多个商品唯一码，以逗号隔开" />
			},
			width: 150,
			render: (text, record) => (
				// <span onClick={() => handleOpenOrderDetailVisible(record)} className="common-color2">
				// 	{text}
				// </span>
				<span className="common-color2">{text}</span>
			)
		},
		{
			name: "售后单",
			code: "afterSalesOrderNo",
			search: {
				order: 3,
				code: "afterSalesOrderNos",
				content: () => <BatchSuffixInput autoMultiLine allowClear clearable placeholder="多个售后单，以逗号隔开" />
			},
			width: 150,
			render: (text, record) => <span className="common-color2">{text}</span>
		},

		{
			name: "系统订单号",
			code: "systemNo",
			search: {
				order: 4,
				code: "systemNos",
				content: () => <BatchSuffixInput autoMultiLine allowClear clearable placeholder="多个系统订单号，以逗号隔开" />
			},
			width: 150,
			render: (text, record) => <span className="common-color2">{text}</span>
		},
		{
			name: "退货员",
			code: "pickerName",
			search: {
				code: "pickerName",
				order: 7,
				content: () => {
					return <TakeGoodsSelect value={takeGoods} params={{ businessType: 4 }} valueKey="name" placeholder="退货员" onChange={handleTakeGoodsChange} />;
				}
			},
			width: 100
		},
		{
			name: "退货状态",
			code: "returnStatus",
			render: value => (
				<span>
					{refundStatus.map(item => {
						if (item.value == value) {
							return (
								// <NumText as="s1" type={item.value == 1 ? "success" : item.value == 2 ? "warning" : "error"} num={item.label} />
								<NumText as="s1" key={item.value} num={item.label} />
							);
						}
					})}
				</span>
			),
			search: {
				order: 1,
				content: () => <Select allowClear placeholder="退货状态" options={refundStatus} />
			},
			width: 100
		},
		{
			name: "退货方式",
			code: "refundMethod",
			render: value => (
				<span>
					{refundMethod.map(item => {
						if (item.value == value) {
							return (
								// <NumText as="s1" type={item.value == 1 ? "success" : item.value == 2 ? "warning" : "error"} num={item.label} />
								<NumText as="s1" key={item.value} num={item.label} />
							);
						}
					})}
				</span>
			),
			search: {
				order: 2,
				content: () => <Select allowClear placeholder="退货方式" options={refundMethod} />
			},
			width: 100
		},
		{
			name: "采购拿货金额",
			code: "purchasePrice",
			render: text => (
				<span>
					<span style={{ color: "rgba(240, 61, 41, 1)" }}>
						{(text || text == 0) ? `￥${text.toFixed(2)}` : ""}
					</span>
				</span>
			),
			width: 120
		},
		{
			name: "实际退货金额",
			code: "actualReturnPrice",
			render: text => (
				<span>
					<span style={{ color: "rgba(240, 61, 41, 1)" }}>
					 	{(text || text == 0) ? `￥${text.toFixed(2)}` : ""}
					</span>
				</span>
			),
			width: 120
		},
		{
			name: "供应商",
			code: "supplierName",
			search: {
				code: "supplierName",
				order: 8,
				content: () => <Input allowClear placeholder="供应商名称" />
			},
			width: 100
		},
		{
			name: "供应商区域编码",
			code: "supplierAreaName",
			search: {
				order: 8,
				code: "supplierAreas",
				content: () => (
					<AreaCodeSelect
						origin="true"
						size="middle"
						placeholder="区域编码"
						mode="multiple"
						options={areaOption.current}
						showArrow={false}
						maxTagCount={1}
						style={{ lineHeight: "22px" }}
					/>
				)
			},
			width: 150
		},
		{
			name: "销售出库单号",
			code: "outboundNo",
			search: {
				order: 5,
				code: "outboundNos",
				content: () => <BatchSuffixInput autoMultiLine allowClear clearable placeholder="多个销售出库单号，以逗号隔开" />
			},
			width: 150,
			render: (text, record) => <span className="common-color2">{text}</span>
		},
		{
			name: "店铺订单号",
			code: "shopOrderNo",
			width: 150,
			render: (text, record) => <span className="common-color2">{text}</span>
		},
		{
			name: "拆包物流单号",
			code: "logisticsNo",
			search: {
				order: 6,
				code: "logisticsNos",
				content: () => <BatchSuffixInput autoMultiLine allowClear clearable placeholder="多个拆包物流单号，以逗号隔开" />
			},
			width: 150
		},
		{
			name: "店铺",
			code: "shopName",
			width: 150
		},
		{
			name: "创建时间",
			code: "createTime",
			render: text => (text ? <div>{moment(text).format("YYYY-MM-DD HH:mm:ss")}</div> : ""),
			search: {
				order: 9,
				span: 6,
				group: [
					{
						span: 9,
						code: "timeType",
						content: () => (
							<Select
								allowClear
								origin={origin}
								defaultValue={1}
								className="width-full"
								placeholder="选择日期"
								options={[
									{
										value: 1,
										label: "创建时间"
									},
									{
										value: 2,
										label: "完成时间"
									},
									{
										value: 4,
										label: "支付时间"
									}
								]}
							/>
						)
					},
					{
						span: 15,
						keys: ["createTimeBegin", "createTimeEnd"],
						code: "times",
						content: () => <RangePicker format={dateFormat} showTime placeholder={["开始时间", "结束时间"]} />
					}
				]
			},
			width: 200
		},
		{
			name: "完结时间",
			code: "completionTime",
			width: 200,
			render: text => (text ? <div>{moment(text).format("YYYY-MM-DD HH:mm:ss")}</div> : "")
		},
		{
			name: "拒绝原因",
			code: "refusalReason",
			width: 250,
			render: (text, record) => (
				<span>
					{record.returnStatus == 3 && (
						<span>
							{refuseType.map(item => {
								if (item.value == record.refusalType) {
									return <span>{item.label}</span>;
								}
							})}
							{text}
						</span>
					)}
				</span>
			)
		},
		{
			name: "退货备注",
			code: "refundRemark",
			width: 200,
		},
		{
			name: '退款支付方式',
			code: "payMeth",
			search: {
				order: 81,
				code: "payMeths",
				content: () => <Select mode="tags" maxTagCount={1} allowClear placeholder="退款支付方式" options={payMethOptions} />
			},
			width: 120,
			render: text => payMethMap[text]
		},
		{
			name: '账单流水号',
			code: "tradeNos",
			search: {
				order: 190,
				code: "tradeNos",
				content: () => <BatchSuffixInput
				clearable
				allowClear
				autoMultiLine
				maxItem={500}
				modalProps={{
					title: "批量输入"
				}}
				placeholder="账单流水号"
				message="分行输入内容，提交后主页面输入框会按照逗号自动隔开，点击查询可批量查询。"
				areaPlaceholder="每行输入1个内容，最多500个，例如:&#10;1272572508553111112223&#10;1272572512332111112226"
			/>
			},
			width: 160,
			render: (_, record) => (
			 <div>
				<div>{record.tradeNo}</div>
				<div>{record.payTime}</div>
			 </div>
			),
		},
	];
	return { defaultColumns };
};
